<template>
  <div class="bk_box">
    <div class="bk_left" style="width:280px;">
      <bk-left />
    </div>
    <div class="bk_resize" title="收缩侧边栏">
      <span>⋮</span>
    </div>
      <div class="bk_mid" style="width: calc(100% - 290px);">
      <el-container class="section pdbot_none">
        <el-header height="height_auto">
          <form-panel
            ref="searchform"
            formkey="SEARCHFORM"
          >
            <template slot="cfg_search_button">
              <el-button type="text" icon="el-icon-search" @click="getSearchData">搜索</el-button>
              <el-button type="text" icon="el-icon-">重置</el-button>
            </template>
          </form-panel>
        </el-header>
        <el-main>
          <gridPage :config='gridConfig' ref='grid'/>
        </el-main>
      </el-container>
    </div>
    <vxe-modal v-model="addwin" width="500px" resize>
      <form-panel
        ref="useraddform"
        formkey="USER_MANAGER"
        buttons="save"
        />
    </vxe-modal>
  </div>
</template>
<script>
import bkLeft from './left'
import gridPage from '@/components/TablePage/gridPage2'
import PsTreeSelect from '@/components/psTree/PsTreeSelect'
import formpanel from '@/components/formpanel'
import request from '@/utils/requestutil'
export default {
  components: {
    bkLeft,
    'form-panel': formpanel,
     gridPage
  },
  data() {
    return {
      addwin:false,
      gridConfig:{
        settings:{
          flag:'TEST_APP_USER',
        },
        odel: '',
        options:{
          treeConfigKey: '',
          checkType: 'check',//check // no
          isEdit: false,//是否行内编辑
          isIndex:true,//是否有索引
          isSort:false,//是否拖拽排序
          tableToolbar: {

            zoom: true,
            buttons: [
              { code: 'btnDemo1', name: '新增', icon: 'fa fa-plus',handler:this.addNew },
              { code: 'btnDemo2', name: '编辑', icon: 'fa fa-plus',handler:this.editRow },
              { code: 'btnDemo2', name: '追加按钮3', icon: 'fa fa-plus' },
            ]
          }
      },
      },
      
    }
  },
  mounted() {
    this.dragControllerDiv();
  },
  methods: {
    editRow(){
      let selectrows=this.$refs.grid.getSelected();
      console.log(selectrows)
    },
    addNew(){
      this.addwin=true;
      console.log(3243243)
    },
    createRightMenu(params) {
      var obj = {
        label: '新增',
        onClick: () => {
          console.log(arguments)
        }
      }
      params.items = [obj]
      return
    },
    getSearchData() {
      const s = this.$refs.searchform.getData()
      const { PromiseResult } = s
      console.log(s)
      console.log(PromiseResult)
    },
    getData() {
      request({
        url: '',
        data: {},
        method: 'post'
      }).then(data => {

      })
    },
     dragControllerDiv: function () {
      var resize = document.getElementsByClassName("bk_resize");
      var left = document.getElementsByClassName("bk_left");
      var mid = document.getElementsByClassName("bk_mid");
      var box = document.getElementsByClassName("bk_box");
      for (let i = 0; i < resize.length; i++) {
        // 鼠标按下事件
        resize[i].onmousedown = function (e) {
          // 颜色改变提醒
          resize[i].style.background = "#E4E9EF";
          var startX = e.clientX;
          resize[i].left = resize[i].offsetLeft;
          // 鼠标拖动事件
          document.onmousemove = function (e) {
            var endX = e.clientX;
            var moveLen = resize[i].left + (endX - startX); // （endx-startx）=移动的距离。resize[i].left+移动的距离=左边区域最后的宽度
            var maxT = box[i].clientWidth - resize[i].offsetWidth; // 容器宽度 - 左边区域的宽度 = 右边区域的宽度

            if (moveLen < 32) moveLen = 32; // 左边区域的最小宽度为32px
            if (moveLen > maxT - 150) moveLen = maxT - 150; // 右边区域最小宽度为150px

            resize[i].style.left = moveLen; // 设置左侧区域的宽度

            for (let j = 0; j < left.length; j++) {
              left[j].style.width = moveLen + "px";
              mid[j].style.width = box[i].clientWidth - moveLen - 10 + "px";
            }
          };
          // 鼠标松开事件
          document.onmouseup = function (evt) {
            // 颜色恢复
            resize[i].style.background = "#f6f7f97a";
            document.onmousemove = null;
            document.onmouseup = null;
            resize[i].releaseCapture && resize[i].releaseCapture(); // 当你不在需要继续获得鼠标消息就要应该调用ReleaseCapture()释放掉
          };
          resize[i].setCapture && resize[i].setCapture(); // 该函数在属于当前线程的指定窗口里设置鼠标捕获
          return false;
        };
      }
    }
  },
 
}
</script>
